package org.sixtythousand.joker.util;

import java.util.concurrent.CompletableFuture;

/**
 * @author zhoulk
 * @date 2023/10/13 10:43
 * @desc
 */
public interface Callback {


    default void succeeded(Object data) {
    }

    default Runnable asyncSucceeded(Object data) {
        // todo
       throw new RuntimeException("not support async");
    }

    default void completeWith(CompletableFuture<?> completable) {
        completable.whenComplete((o, x) ->
        {
            if (x == null) {
                succeeded();
            } else {
                failed(x);
            }

        });
    }

    default void succeeded() {

    }

    default void failed(Throwable th) {

    }
}
